package com.maxmlr.music.song.controller;

import com.maxmlr.music.common.base.BaseController;
import com.maxmlr.music.common.bean.ResultBean;
import com.maxmlr.music.song.entity.Singer;
import com.maxmlr.music.song.param.SingerInfoParam;
import com.maxmlr.music.song.service.SingerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.Arrays;

/**
 * @author max
 * @version 1.0
 * @ClassName SingerController
 * @Description 控制器
 * @Copyright Copyright (c) 2020: www.maxmlr.com.
 * @since 2020-06-07
 */
@Slf4j
@RestController
@Api(value = "/song/singer", tags = "Singer 控制器")
@RequestMapping("/song/singer")
public class SingerController extends BaseController<SingerService, Singer> {

    @Autowired
    public SingerService service;

    /**
     * @Description 获取歌手信息
     * @author max
     * @since 2019-05-11
     */
    @GetMapping("/getSingerInfoById")
    @ApiOperation(value = "/getSingerInfoById", notes = "获取分页列表")
    public ResultBean<SingerInfoParam> getSingerInfoById(Integer id) {
        return ResultBean.ok(service.getSingerInfoById(id));
    }

    /**
     * 保存
     *
     * @param singer
     * @return ResultBean<Boolean>
     */
    @PostMapping
    @RequiresPermissions("song:singer:add" )
    public ResultBean<Boolean> save(SingerInfoParam param) {
        return ResultBean.ok(service.saveParam(param));
    }

    /**
     * 修改
     *
     * @param singer
     * @return ResultBean<Boolean>
     */
    @PutMapping
    @RequiresPermissions("song:singer:edit" )
    public ResultBean<Boolean> update(SingerInfoParam param) {
        return ResultBean.ok(service.updateParamById(param));
    }

    /**
     * 删除
     *
     * @param id
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/remove/{id}" )
    @RequiresPermissions("song:singer:remove" )
    public ResultBean<Boolean> remove(@PathVariable("id" ) Serializable id) {
        return ResultBean.ok(service.removeById(id));
    }

    /**
     * 批量删除
     *
     * @param ids
     * @return ResultBean<Boolean>
     */
    @DeleteMapping("/batch-remove")
    @RequiresPermissions("song:singer:batch-remove")
    public ResultBean<Boolean> batchRemove(@RequestParam("ids[]") Serializable[] ids){
        return ResultBean.ok(service.removeByIds(Arrays.asList(ids)));
    }
}
